package com.hns.can.master.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.master.service.HolidayParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.hns.can.common.domain.GridPage;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.util.ResponseUtil;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/holidayParam")
public class HolidayParamController  extends BaseController {
    @Autowired
    private HolidayParamService holidayParamService; // 注入holidayParamService

    /**
     * @param qyear
     * @param qholiday
     * @throws Exception
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2014-10-30
     * @功能说明：节假日参数设置 - 搜索节假日列表
     */
    @RequestMapping("/searchHolidayPage")
    @ResponseBody
    public Object searchHolidayPage(
            @RequestParam(value="qyear",required=false) String qyear,
            @RequestParam(value="qholiday",required=false) String qholiday) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        String corpId = user.getCorpId();
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("corpId", corpId);
        paraMap.put("qyear", qyear);
        paraMap.put("qholiday", qholiday);
        Pagination page = holidayParamService.searchHolidayPage(paraMap);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }

    /**
     * @param holidayId
     * @param strDate
     * @throws Exception
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2014-10-29
     * @功能说明：节假日参数设置 - 重置节假日为非节假日、工作日
     */
    @RequestMapping("/resetHoliday")
    @ResponseBody
    public Object resetHoliday(
            @RequestParam(value="holidayId",required=false) String holidayId,
            @RequestParam(value="strDate",required=false) String strDate) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        String corpId = user.getCorpId();
        holidayParamService.resetHoliday(corpId, holidayId, strDate);
        return this.getReturnResult("重置成功");
    }

    /**
     * @param holidayIds
     * @param strDates
     * @param request
     * @param response
     * @throws Exception
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2014-10-29
     * @功能说明：节假日参数设置 - 批量重置节假日为非节假日、工作日
     */
    @RequestMapping("/resetHolidays")
    @ResponseBody
    public Object resetHolidays(
            @RequestParam(value="holidayIds",required=false) List<String> holidayIds,
            @RequestParam(value="strDates",required=false) List<String> strDates,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        String corpId = user.getCorpId();
        holidayParamService.resetHolidays(corpId, holidayIds, strDates);
        return this.getReturnResult("批量重置成功");
    }

    /**
     * @param holidays
     * @param beginDates
     * @param endDates
     * @param workDayInds
     * @throws Exception
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2014-10-30
     * @功能说明：节假日参数设置 - 设定节假日
     */
    @RequestMapping("/setHolidays")
    @ResponseBody
    public Object setHolidays(
            @RequestParam(value="holidays",required=false) List<String> holidays,
            @RequestParam(value="beginDates",required=false) List<String> beginDates,
            @RequestParam(value="endDates",required=false) List<String> endDates,
            @RequestParam(value="workDayInds",required=false) List<String> workDayInds) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        String corpId = user.getCorpId();
        holidayParamService.setHolidays(corpId, holidays, beginDates, endDates, workDayInds);
        return this.getReturnResult("设定节假日成功");
    }
}
